try {
    Type.registerNamespace('FinProdInMakeUtil');
    
    FinProdInMakeUtil.getUnitBitnumber = function(unitid) {
        var wheresql = "where pk_measdoc='" + unitid + "'";
        var bitnumber = 0;
        if(!NCMMPubUtil.isTableExist(MeasdocVO)) {
            return;
        }
        NCMMPubUtil.queryVO(MeasdocVO, wheresql, function(data) {
            if(typeof(data) == 'undefined' || data == null || data.length == 0) {
                return;
            }
            var unitData = eval(data);
            if(unitData.length > 0) {
                bitnumber = unitData[0].bitnumber;
            } else {
                return;
            }
        });
        return bitnumber;
    };
    
    /**
     *计算主数量 
     */
    FinProdInMakeUtil.getNum =  function (nastnum,vchange){
        if(nastnum == null || nastnum == "") {
            nastnum += "00.00000";
        } else {
            nastnum = parseFloat(nastnum);
        }
        if(vchange == null || vchange == "") {
            vchange += "1.00000";
        } else {
            vchange = parseFloat(vchange);
        }
        var num=nastnum.mul(vchange);
        return num;
    }
    
      /**
      *主数量除以换算率得辅数量 
      * @param {Object} nnum
      * @param {Object} vchange
      */
    FinProdInMakeUtil.getAstnum =  function (nnum,vchange){
        if(nnum == null || nnum == "") {
            nnum += "00.00000";
        } else {
            nnum = parseFloat(nnum);
        }
         if(vchange == null || vchange == "") {
            vchange += "1.00000";
        } else {
            vchange = parseFloat(vchange);
        }
        var nastum=nnum.div(vchange);
        return nastum;
    }
    
    //计算浮动换算率
	FinProdInMakeUtil.deleteaftersubmit = function(vos) {
	    console.log($jsonToString(vos));
	    var tblname = FinProdInMakeVO.prototype.getTableName();
	    var sql = "delete from " + tblname;
	    var pkcol = FinProdInMakeVO.prototype.getPrimaryAttr();
	    sql = sql + " where " + pkcol.name + " in (";
	    for (var i = 0;i < vos.length; i++) {
	        var pk_scan = vos[i]["pk_scan"];
	        sql = sql + "'" + pk_scan + "',";
	    }
	    sql = sql.substring(0,sql.length - 1) + ")";
	    console.log($jsonToString(sql));
	    var param = {
	        db: NCMMPubUtil.DatabaseName,
	        sql: sql
	    }
	    $sqlite.execSql(param);
	}
			//校验输入数字的精度是否正确
	FinProdInMakeUtil.validateNumScale = function(numStr, pk_measure) {
			var returnflag;
			var scale = FinProdInMakeUtil.getScaleDigit(pk_measure);
			if(scale == null || scale == "") {
				returnflag = true;
				return returnflag;
			}
			var strs = numStr.split(".");
			if(strs.length == 1) {
				returnflag = true;
			} else if(strs.length == 2 && strs[1].length <= scale) {
				returnflag = true;
			} else {
				returnflag = false;
			}
			return returnflag;
		}
		//判断输入的字符串是否是数字，包括正、负、0
	FinProdInMakeUtil.isNumber = function(inputstr) {
		var zregex = /^\d+(\.\d*)?$/;
		var fregex = /^((-\d*(\.\d*)?)|(0+(\.0*)?))$/;
		if(inputstr == null || inputstr == "") {
			return false;
		}
		if(!zregex.test(inputstr) && !fregex.test(inputstr)) {
			return false;
		}
		return true;
	}
	FinProdInMakeUtil.getScaleDigit = function(pk_measure) {
			if(!NCMMPubUtil.isTableExist(MeasdocVO)) {
				return null;
			}
			var scale = "";
			var wheresql = "where pk_measdoc='" + pk_measure + "'"
			NCMMPubUtil.queryVO(MeasdocVO, wheresql, function(data) {
				if(data != null && data != "" && data != "[]") {
					var meajson = $stringToJSON(data);
					scale = meajson[0].bitnumber;
				}
			});
			return scale;
	}
    
    //计算浮动换算率
	FinProdInMakeUtil.getvchangerate = function(nnum, nastnum) {
	    var vchangerate;
	    var num = nnum / nastnum;
	    num = num.toFixed(3);
	    vchangerate = num.toString()+"/1";
	    return vchangerate;
	}
	
	// 由主数量和换算率计算数量
	FinProdInMakeUtil.getNastum = function(nnum, vchangerate) {
		if(nnum == null || nnum == "") {
			nnum = "0.00000";
		} else {
			nnum = parseFloat(nnum);
		}
		if(vchangerate == null || vchangerate == "") {
			vchangerate = "1.00000";
			var nastum = nnum / vchangerate;
		} else {
			var vchangearray = vchangerate.split("/");
			if(vchangearray == null || vchangearray.length != 2)
				return nnum;
			var up = parseFloat(vchangearray[0]);
			var down = parseFloat(vchangearray[1]);
			if(up == null || down == null)
				return nnum;
			var nastum = (nnum * down) / up;
		}
		return nastum;
	}
	// 由主数量和换算率计算数量
	FinProdInMakeUtil.getNastum = function(nnum, vchangerate) {
		if(nnum == null || nnum == "") {
			nnum = "0.00000";
		} else {
			nnum = parseFloat(nnum);
		}
		if(vchangerate == null || vchangerate == "") {
			vchangerate = "1.00000";
			var nastum = nnum / vchangerate;
		} else {
			var vchangearray = vchangerate.split("/");
			if(vchangearray == null || vchangearray.length != 2)
				return nnum;
			var up = parseFloat(vchangearray[0]);
			var down = parseFloat(vchangearray[1]);
			if(up == null || down == null)
				return nnum;
			var nastum = (nnum * down) / up;
		}
		return nastum;
	}

	// 由数量和换算率计算主数量
	FinProdInMakeUtil.getNum = function(nastnum, vchangerate) {
			if(nastnum == null || nastnum == "") {
				nastnum = "0.00000";
			} else {
				nastnum = parseFloat(nastnum);
			}
			if(vchangerate == null || vchangerate == "") {
				vchangerate = "1.00000";
				var num = nastnum * vchangerate;
			} else {
				var vchangearray = vchangerate.split("/");
				if(vchangearray == null || vchangearray.length != 2)
					return nastnum;
				var up = parseFloat(vchangearray[0]);
				var down = parseFloat(vchangearray[1]);
				if(up == null || down == null)
					return nastnum;
				var num = (nastnum * up) / down;
			}
			return num;
		}
			//设置数字精度
	FinProdInMakeUtil.getScaleNum = function(numStr, pk_measure) {
			if(!NCMMPubUtil.isTableExist(MeasdocVO)) {
				return numStr;
			}
			var num;
			var wheresql = "where pk_measdoc='" + pk_measure + "'"
			NCMMPubUtil.queryVO(MeasdocVO, wheresql, function(data) {
				num = parseFloat(numStr);
				if(data != null && data != "" && data != "[]") {
					var meajson = $stringToJSON(data);
					var scale = meajson[0].bitnumber;
					num = num.toFixed(scale);
				}
			});
			return num;
		}
    
    FinProdInMakeUtil.openDropDownList = function(controlid) {
		$menu.openDropDownList({
			"controlid": controlid, //目标控件的id
			"dropDownListWidth": "100", //菜单项的宽度
			"background": "#f2f2f2",
			//"background-image":"app.png",
			"color": "#ee4311",
			"font-size": "12",
			"halign": "center", //right  center
			"split-color": "#ee4311",
			//"margin-left":"10",
			"panelstyle": "round-div",
			"border-color": "#ee4311",
			//"showtype":"right",
			"dropItemsArray": [{
				"id": "id_homepage",
				"name": "主菜单", //菜单项名称
				"action": "gotohomepage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_datamanage",
				"name": "数据管理", //菜单项名称
				"action": "gotodatamanage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_setting",
				"name": "业务设置", //菜单项名称
				"action": "setting()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_logout",
				"name": "注销", //菜单项名称
				"action": "logout()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_scanlist",
				"name": "扫描记录", //菜单项名称
				"action": "gotoscanlist()" //点击该菜单项时执行的JS方法
			}]
		});
    }
    
    FinProdInMakeUtil.openDropDownListForScan = function(controlid) {
		$menu.openDropDownList({
			"controlid": controlid, //目标控件的id
			"dropDownListWidth": "100", //菜单项的宽度
			"background": "#f2f2f2",
			//"background-image":"app.png",
			"color": "#ee4311",
			"font-size": "12",
			"halign": "center", //right  center
			"split-color": "#ee4311",
			//"margin-left":"10",
			"panelstyle": "round-div",
			"border-color": "#ee4311",
			//"showtype":"right",
			"dropItemsArray": [{
				"id": "id_homepage",
				"name": "主菜单", //菜单项名称
				"action": "gotohomepage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_datamanage",
				"name": "数据管理", //菜单项名称
				"action": "gotodatamanage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_setting",
				"name": "业务设置", //菜单项名称
				"action": "setting()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_logout",
				"name": "注销", //菜单项名称
				"action": "logout()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_scanlist",
				"name": "扫描记录", //菜单项名称
				"action": "gotoscanlistForScan()" //点击该菜单项时执行的JS方法
			}]
		});
    }
    
	function gotohomepage() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.HomePage", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function gotodatamanage() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.DM_main", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function setting() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.BusinessSettingPage", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function logout() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.LoginPage", //目标页面（首字母大写）全名
			"isKeep": "false", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
	function gotoscanlist() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.FinProdInMakeList", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
	function gotoscanlistForScan() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.FinProdInMakeList", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
} catch(e) {
	$e(e);
}